<template>
  <el-dialog
    :visible="visible"
    :title="title"
    class="mounted-catalog-dialog"
    align-center
    @opened="handleDialogOpen"
    @close="closeDialog"
  >
    <el-form
      :model="catalogForm"
      :rules="catalogRules"
      ref="catalogFormRef"
      label-width="80px"
    >
      <el-form-item label="目录名称" prop="catalogName">
        <el-input v-model="catalogForm.catalogName" />
      </el-form-item>
      <el-form-item label="数据名称" prop="dataName">
        <el-input v-model="catalogForm.dataName" />
      </el-form-item>
      <el-form-item label="服务类型" prop="serviceType">
        <el-select
          v-model="catalogForm.serviceType"
          placeholder="请选择"
          clearable
        >
          <el-option
            v-for="(item, index) in serviceTypeDict"
            :key="index"
            :label="item.label"
            :value="item.value"
            :disabled="item.value === 'socialmanager'"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="服务地址" prop="serviceUrl">
        <el-input v-model="catalogForm.serviceUrl" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="onSubmit"> 确定</el-button>
        <el-button @click="closeDialog">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import type { PropType } from 'vue'
import type { OptionData } from '@/utils/type'

const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
  serviceTypeDict: {
    type: Array as PropType<OptionData[]>,
    default: () => [],
  },
  catalogInfo: {
    type: Object,
    default: () => {},
  },
})

const catalogForm = reactive({
  catalogName: '',
  dataName: '',
  serviceType: '',
  serviceUrl: '',
})

const catalogRules = reactive({
  catalogName: [
    {
      required: true,
      message: '目录名称不能为空',
      trigger: 'blur',
    },
  ],
  dataName: [
    {
      required: true,
      message: '数据名称不能为空',
      trigger: 'blur',
    },
  ],
})

const catalogFormRef = ref()

const title = ref('服务挂载')

const emit = defineEmits(['closeDialog', 'updateCatalog'])

const closeDialog = () => {
  emit('closeDialog')
}

const onSubmit = () => {}
const handleDialogOpen = () => {
  if (props.catalogInfo.value) {
    catalogFormRef.value.resetField()
  }
}
</script>

<style lang="scss">
.mounted-catalog-dialog {
  //width: 562px;
  //height: 443px;
  //background: #ffffff;
  border-radius: 4px;
  .el-dialog__body {
    padding-bottom: 0 !important;
  }
  .el-dialog__footer {
    padding-top: 30px !important;
    border-top: 1px solid #e5e5e5;
  }

  .el-dialog__header {
    border-bottom: 1px solid #e5e5e5;

    .el-dialog__title {
      width: 64px;
      height: 16px;
      font-size: 16px;
      font-weight: bold;
      color: #27475f;
    }
  }

  .el-form {
    .el-form-item {
      min-height: 42px;
      margin-bottom: 21px;
      align-items: center;
    }

    .el-cascader {
      width: 100%;
    }

    .el-select {
      width: 100%;
    }
  }

  .dialog-footer {
    width: 100%;
    height: 100%;
    text-align: center;
  }
}
</style>
